<!-- 实时监控 -->
<template>
  <div class="mapStatistics">
    <!-- 弹框 -->
    <el-dialog :visible.sync="totalCountVisible" top="5vh" :append-to-body="true">
      <div slot="title">
        <p>站点数量</p>
      </div>
      <el-table
        :data="stationsInfo"
        border
        :header-cell-style="{color: '#909399', backgroundColor: '#F5F7FA'}"
        style="width: 100%"
      >
        <el-table-column prop="monitorSystem" label="系统号" width="100" align="center"></el-table-column>
        <el-table-column prop="waterStation" label="站点名称" align="center"></el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog :visible.sync="excessStationsVisible" top="4vh" width="80%" :append-to-body="true">
      <div slot="title">
        <p>超标站点</p>
      </div>
      <el-table :data="excessStations" v-loading="loading" border style="width: 100%">
        <el-table-column prop="stationName" label="水站名称" width="100" align="center"></el-table-column>
        <el-table-column prop="excessFactorList" label="超标因子" align="center">
          <el-table-column prop="factor" label="因子" align="center">
            <template slot-scope="scope">
              <p
                class="excessFactor"
                v-for="item in scope.row.excessFactorList"
                :key="item.factor"
              >{{item.factor}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="realConc" label="监测值" align="center">
            <template slot-scope="scope">
              <p
                class="TableWarnRed"
                v-for="item in scope.row.excessFactorList"
                :key="item.factor"
              >{{item.realConc }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="standard" label="标准值" align="center">
            <template slot-scope="scope">
              <p
                class="excessFactor"
                v-for="item in scope.row.excessFactorList"
                :key="item.factor"
              >{{item.standard}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="standard" label="超标倍数" align="center">
            <template slot-scope="scope">
              <p
                class="excessFactor TableWarnRed"
                v-for="item in scope.row.excessFactorList"
                :key="item.factor"
              >{{ item.excessiveMultiple }}</p>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="operator" label="运维人员" align="center"></el-table-column>
        <el-table-column prop="phone" label="联系方式" width="120" align="center"></el-table-column>
      </el-table>
    </el-dialog>

    <!-- 设备故障弹窗 -->
    <el-dialog :visible.sync="faultDevicesVisible" width="60%" :append-to-body="true">
      <div slot="title">
        <p>设备故障</p>
      </div>
      <el-table
        :data="faultDevices"
        v-loading="loading"
        border
        :header-cell-style="{color: '#909399', backgroundColor: '#F5F7FA'}"
        style="width: 100%"
      >
        <el-table-column prop="stationName" label="水站名称" width="100" align="center"></el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="deviceName" label="设备名称" width="120" align="center"></el-table-column>
        <el-table-column prop="reason" label="故障原因" align="center">
          <template slot-scope="scope">
            <p v-for="item in scope.row.reason" :key="item">{{item}}</p>
          </template>
        </el-table-column>
        <el-table-column prop="operator" label="运维人员" align="center"></el-table-column>
        <el-table-column prop="phone" label="联系方式" align="center"></el-table-column>
      </el-table>
    </el-dialog>
    <div class="statisItem" @click="totalCount">
      <div class="staticIcon blue pointer">
        <img src="/img/statistics/totalCount.png" alt />
      </div>
      <div class="staticText pointer">
        <p class="name">站点数量</p>
        <p class="value">
          {{statisticsData.stationCount}}
          <span class="unit">个</span>
        </p>
      </div>
    </div>
    <div class="statisItem">
      <div class="staticIcon yellow pointer" @click="openExcessStations">
        <img src="/img/statistics/excessCount.png" alt />
      </div>
      <div class="staticText pointer" @click="openExcessStations">
        <p class="name">超标站点</p>
        <p class="value">
          {{statisticsData.exceedStandard}}
          <span class="unit">个</span>
        </p>
      </div>
    </div>
    <div class="statisItem">
      <div class="staticIcon green">
        <img src="/img/statistics/complianceRate.png" alt />
      </div>
      <div class="staticText">
        <p class="name">达标率</p>
        <p class="value">{{(statisticsData.exceedRate * 100).toFixed(2)}}%</p>
      </div>
    </div>
    <div
      class="statisItem"
      v-if="!userInfo.roles.includes('manager') && !userInfo.roles.includes('environmentalDirector')"
    >
      <div class="staticIcon red pointer" @click="openFaultDevices">
        <img src="/img/statistics/deviceFailureCount.png" alt />
      </div>
      <div class="staticText pointer" @click="openFaultDevices">
        <p class="name">设备故障的</p>
        <p class="value">
          {{statisticsData.malfunction}}
          <span class="unit">个</span>
        </p>
      </div>
    </div>
    <div
      class="statisItem"
      v-if="!userInfo.roles.includes('manager') && !userInfo.roles.includes('environmentalDirector')"
    >
      <div class="staticIcon violet">
        <img src="/img/statistics/deviceAbnormalRate.png" alt />
      </div>
      <div class="staticText">
        <p class="name">故障率</p>
        <p class="value">{{(statisticsData.malfunctionRate * 100).toFixed(2)}}%</p>
      </div>
    </div>
    <div
      class="statisItem"
      v-if="!userInfo.roles.includes('manager') && !userInfo.roles.includes('environmentalDirector')"
    >
      <div class="staticIcon color-4ed0d8">
        <img src="/img/statistics/effectiveDataCount.png" alt />
      </div>
      <div class="staticText">
        <p class="name">有效数据量</p>
        <p class="value">
          {{'暂无'}}
          <span class="unit">个</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import standard from "@/plugins/standard.js";
import common from "@/plugins/common";
import posts from "@/plugins/request";
export default {
  name: "mapStatistics",
  data() {
    return {
      totalCountVisible: false,
      excessStationsVisible: false,
      faultDevicesVisible: false,
      loading: false,
      common,
      standard,
    };
  },
  computed: {
    ...mapGetters({
      userInfo: "getUserInfo",
      statisticsData: "getStatisticsData",
      faultDevices: "getFaultDevices",
      excessStations: "getExcessStations",
      stationsInfo: "getStationsInfo",
    }),
  },
  methods: {
    ...mapActions([
      "fetchFaultDevices",
      "fetchExcessStations",
      "fetchStationsInfo",
    ]),
    async totalCount() {
      this.totalCountVisible = true;
      this.loading = true;
      await this.fetchStationsInfo();
      this.loading = false;
    },
    async openExcessStations() {
      this.excessStationsVisible = true;
      this.loading = true;
      await this.fetchExcessStations();
      this.loading = false;
    },
    async openFaultDevices() {
      this.faultDevicesVisible = true;
      this.loading = true;
      await this.fetchFaultDevices();
      this.loading = false;
    },
    hasUnit(factor, value) {
      return factor === "pH" || factor === "ph" ? value : value + " mg/L";
    },
    standardHasUnit(factor, standard) {
      return factor === "pH" || factor === "ph"
        ? standard.min + " ~ " + standard.max
        : standard + " mg/L";
    },
  },
};
</script>
<style scoped>
.mapStatistics {
  width: 100%;
  height: 100%;
  display: flex;
  padding: 10px 0;
}
.mapStatistics .statisItem {
  position: relative;
  display: flex;
  justify-content: center;
  /* width: calc(100% / 6); */
  flex: 1;
  font-size: 16px;
  padding: 20px;
  text-align: center;
  color: #313b46;
}
.mapStatistics .statisItem::after {
  content: "";
  position: absolute;
  right: 0;
  top: 25%;
  width: 1px;
  height: 50%;
  background-color: #efefef;
}
.mapStatistics .statisItem:last-child::after {
  content: none;
}

.staticIcon {
  position: relative;
  float: left;
  width: 60px;
  border-radius: 50%;
  height: 60px;
}
.staticIcon img {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
}
.staticText {
  box-sizing: border-box;
  float: left;
  /* width: calc(100% - 60px); */
  height: 100%;
  padding-left: 18px;
  transition: 0.3s ease-in;
}
.staticText .name {
  font-size: 14px;
  line-height: 30px;
}
.staticText .value {
  line-height: 26px;
  font-size: 20px;
  color: #313b46;
}
.staticText .value .unit {
  color: #313b46;
  font-size: 12px;
  vertical-align: middle;
}

.statisItem .pointer {
  cursor: pointer;
}
.statisItem .blue {
  background-color: #91b3ff;
}
.statisItem .yellow {
  background-color: #ffbd4b;
}
.statisItem .green {
  background-color: #89e89d;
}
.statisItem .red {
  background-color: #ff7070;
}
.statisItem .violet {
  background-color: #b091ff;
}
.statisItem .color-4ed0d8 {
  background-color: #4ed0d8;
}

@media (max-width: 1600px) {
  .staticText {
    padding-left: 8px;
    text-align: left;
  }
}
@media (max-width: 1400px) {
  .staticIcon {
    width: 40px;
    height: 40px;
  }
  .staticIcon img {
    transform: scale(0.6);
  }
  .staticText {
    padding-left: 4px;
    text-align: center;
  }
  .staticText .name {
    font-size: 12px;
    line-height: 20px;
  }
  .staticText .value {
    line-height: 20px;
    font-size: 14px;
  }
}
</style>
